Here I want to apply the projected neighbors graph visualization to the neural crest dataset that is used in the scVelo demo.
Use the reticulate package to use scVelo from within R:
Extract spliced and unspliced data
Filter genes
Downsample cells to make things easier
Normalize for dimensional reduction
## Warning in if (!class(counts) %in% c("dgCMatrix", "dgTMatrix")) {: the condition
## has length > 1 and only the first element will be used
## Converting to sparse matrix ...
## Normalizing matrix with 977 cells and 4589 genes
Dimensional reduction
Run velocyto on neuro data
Scores of observed and projected states in PC space
Graph visualization on subset of cells from PC coordinates
Graph visualization on subset of cells from gene expression
using common.genes (intersect of overdispersed genes, odsGenes, and genes in velocity output (genes with high correlation b/w spliced and unspliced))
Effects of changing k, distance measure, similarity measure, and similarity threshold:
Using PC generated graph
L1 vs L2 as distance measure:
#using k=10, similarity=cosine, threshold=0.25
k = 10
t = 0
set.seed(1)
graphViz(curr.sub,proj.sub,k,"L1","cosine",t,weighted = TRUE, cell.colors = cell.cols.grph,title = paste("L1 distance,K =",k,"weighted, thresh =",t))
set.seed(1)
graphViz(curr.sub,proj.sub,k,"L2","cosine",t,weighted = TRUE, cell.colors = cell.cols.grph,title = paste("L2 distance,K =",k,"weighted, thresh =",t))
Pearson correlation vs Cosine similarity:
k = 10
t = -1
set.seed(1)
graphViz(curr.sub,proj.sub,k,"L2","cosine",t,weighted = TRUE, cell.colors = cell.cols.grph,title = paste("Cosine similarity,K =",k,"\nweighted, thresh =",t))
set.seed(1)
graphViz(curr.sub,proj.sub,k,"L2","pearson",t,weighted = TRUE, cell.colors = cell.cols.grph,title = paste("Pearson correlation,K =",k,"\nweighted, thresh =",t))
..looks like correlation is more conservative than cosine similarity.
Number of out edges k:
Similarity threshold:
## [1] -1
## [1] "Done finding neighbors"
## [1] "Done making graph"
## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.1061219 min.arrow.size= 0.002122438 max.grid.arrow.length= 0.0610458 done
## [1] 0
## [1] "Done finding neighbors"
## [1] "Done making graph"
## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.1061219 min.arrow.size= 0.002122438 max.grid.arrow.length= 0.0610458 done
## [1] 0.25
## [1] "Done finding neighbors"
## [1] "Done making graph"
## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.1173465 min.arrow.size= 0.002346931 max.grid.arrow.length= 0.0610458 done
## [1] 0.5
## [1] "Done finding neighbors"
## [1] "Done making graph"
## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.09793795 min.arrow.size= 0.001958759 max.grid.arrow.length= 0.0610458 done
## [1] 0.7
## [1] "Done finding neighbors"
## [1] "Done making graph"
## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.09157006 min.arrow.size= 0.001831401 max.grid.arrow.length= 0.0610458 done
## [1] 0.9
## [1] "Done finding neighbors"
## [1] "Done making graph"
## delta projections ... sqrt knn ... transition probs ... done
## calculating arrows ... done
## grid estimates ... grid.sd= 0.09084025 min.arrow.size= 0.001816805 max.grid.arrow.length= 0.0610458 done
Number of out edges k:
L2 distance, cosine similarity, similarity threshold = 0
Similarity threshold:
Consistency score in FDG compared to PCA and UMAP computed on same cell subset
## Warning in vattrs[[name]][index] <- value: number of items to replace is not a
## multiple of replacement length
## [1] "Mean consistency scores for PCA, UMAP, FDG"
## [1] 0.2308163
## [1] 0.2293477
## [1] 0.2097686
## [1] "Median consistency scores for PCA, UMAP, FDG"
## [1] 0.188614
## [1] 0.1907555
## [1] 0.170498